// Include system file
#include "r_cg_can.h"

// Include project file
#include "CAN.h"
#include "fet.h"
#include "nvm.h"
#include "control.h"
#include "faults.h"
#include "Main.h"
#include "Switches.h"
#include "Joystick.h"
#include "Serial.h"
#include "Battery.h"
#include "RemoteCtrlCan.h"

structRemoteCtrlCan stRemoteCtrlCan={0};
void vRemoteCtrlCanFastRxCallBack(UINT16 u16_id_hi,UINT16 u16_id_lo,UINT8 u8_length,UINT8 *pData)
{
	UINT8 i=0;
	if(u16_id_hi==0&&u16_id_lo==0x181&&u8_length==8)
	{
		for(i=0;i<8;i++)
		{
			stRemoteCtrlCan.unRx0x181.Bytes[i] = pData[i];
		}
		stRemoteCtrlCan.stRxCtrl.fRx0x181Update=1;
	}
}

static void vProcRemoteCtrlCanLost(void)//内部调用，掉线逻辑
{
	if(stRemoteCtrlCan.stRxCtrl.fRx0x181Update)
	{
		stRemoteCtrlCan.stRxCtrl.u16Rx0x181LostCnt=0;
		stRemoteCtrlCan.stRxCtrl.fRx0x181Lost=0;
	}
	if(stRemoteCtrlCan.stRxCtrl.u16Rx0x181LostCnt<RemoteCtrlCanLostTime)
	{
		stRemoteCtrlCan.stRxCtrl.u16Rx0x181LostCnt++;
	}
	else
	{
		stRemoteCtrlCan.stRxCtrl.fRx0x181Lost=1;
	}
}
void vRemoteCtrlCanRx(void)//10ms 主循环
{
	vProcRemoteCtrlCanLost();
	if(stRemoteCtrlCan.stRxCtrl.fRx0x181Update)
	{
		stRemoteCtrlCan.stRxCtrl.fRx0x181Update = 0;

		//数据更新,处理数据
	}
}
void vRemoteCtrlCanTx(void)//10ms 主循环
{
	static UINT8 u830msCnt=0;	
	if(++u830msCnt>=3){u830msCnt=0;}
	switch(u830msCnt)
	{
		case 1:
			if(TX_FIFO_PUSH_EN)
			{
				vPushCanTxFifo(&stCanTxFifo,0x0000, 0x0201, 8, &stRemoteCtrlCan.unTx0x201.Bytes[0]);
			}
		break;
		default:
		break;
	}
}



